package com.briup.app02.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.app02.bean.Carousel;
import com.briup.app02.service.ICarouselService;
import com.briup.app02.utils.Message;
import com.briup.app02.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/carousel")
@Api(description = "轮播图相关接口")
@Validated
public class CarouselController {
	@Autowired
	private ICarouselService carouselService;
	
	@GetMapping("query")
	@ApiOperation("查询所有轮播图信息")
	public Message query(String status){
		List<Carousel> list = carouselService.query(status);
		return MessageUtil.success(list);
	}
	
	@PostMapping("saveOrUpdate")
	@ApiOperation(value="保存或更新")
	@ApiImplicitParams({
		@ApiImplicitParam(name="id",value = "主键",paramType = "form"),
        @ApiImplicitParam(name="name",value = "名称",paramType = "form",required = true),
        @ApiImplicitParam(name="introduce",value = "说明",paramType = "form"),
        @ApiImplicitParam(name="url",value = "链接",paramType = "form"),
        @ApiImplicitParam(name="status",value = "状态",paramType = "form"),
})         
	public Message saveOrUpdate(Carousel carousel) {
		carouselService.saveOrUpdate(carousel);
		return MessageUtil.success("操作成功");
	}
	
	@DeleteMapping("deleteById")
	@ApiOperation("根据id删除轮播图信息")
	@ApiImplicitParam(name="id",value = "轮播图id",dataType = "long",paramType = "query",required = true)
	public Message deleteById(long id) {
		carouselService.deleteById(id);
		return MessageUtil.success("删除成功");
	}
}
